package logic

import (
	"context"
	"shuqi-novel/novelrpc/novelrpc"

	"shuqi-novel/api/internal/svc"
	"shuqi-novel/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type StoryAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewStoryAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StoryAddLogic {
	return &StoryAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *StoryAddLogic) StoryAdd(req *types.StoryAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	add, err := l.svcCtx.NovelRpc.StoryAdd(l.ctx, &novelrpc.StoryAddRequest{
		NovelId: req.NovelId,
		Img:     req.Img,
		Title:   req.Title,
		About:   req.About,
		Status:  req.Status,
	})
	if err != nil {
		return &types.Response{
			Message: "添加失败",
			Data:    nil,
			Code:    0,
		}, nil
	}

	return &types.Response{
		Message: "添加成功",
		Data:    add,
		Code:    200,
	}, nil
}
